<template>
  <div>
    <el-row>
      <el-col :span="24" class="addRole">
        <!-- 查询 -->
        <el-popover placement="bottom-start" width="1000" style="margin-right:10px;" trigger="click">
          <el-form :inline="true" :model="search">
              <el-form-item label="图纸编号" >
                  <el-input v-model="search.drawCode"></el-input>
              </el-form-item>
              <el-form-item label="生产令号" >
                  <el-input v-model="search.makeNo"></el-input>
              </el-form-item>
              <el-form-item label="任务流水号" >
                  <el-input v-model="search.taskSerialNo"></el-input>
              </el-form-item>
              <el-form-item label="自定义编码" >
                  <el-input v-model="search.code"></el-input>
              </el-form-item>
              <el-button type="primary" @click="searchBtn">确认</el-button>
          </el-form>
          <el-button slot="reference" type="primary" icon="el-icon-search">查询</el-button>
        </el-popover>
          <!-- <el-button type="primary">插件</el-button> -->
      </el-col>
    </el-row>
    <!-- 29所列表 -->
    <tableList29Screen ref="tableList29" :postData="postData">
      <template v-slot:default="scope" >
        <el-button @click="showDialog('update',scope.row)" type="text" size="small">详情</el-button>
        <el-button @click="confirmHandle(scope.row)" type="text" size="small" v-if="scope.row.isMaterialTailor!==1">
          <el-link type="success">下料</el-link>
        </el-button>
      </template>
    </tableList29Screen>
    <!-- 计划任务详情 -->
    <el-dialog class="bodyNopaddingTop" :title="dialog.title" :visible.sync="dialog.isShow"  v-dialogDrag width="1100px"  @opened="openedDialog">
      <el-tabs v-model="dialog.activeName" @tab-click="dialogHandleClick">
        <el-tab-pane label="详情" name="1">
            <taskDetail29 :detailObj="dialog.formData" :type="dialog.type" :editDisalbe="true"></taskDetail29>
        </el-tab-pane>
        <!-- 工艺编制列表 -->
        <el-tab-pane label="工艺编制" name="6" v-if="dialog.type==='update'">
          <processPlanList ref="processPlanListRef" :drawCode="dialog.drawCode" :formData="dialog.formData" :isApiType="1">
            <template v-slot:default="scope" >
              <el-button @click="showDialog2('update',scope.row)" type="text" size="small">详情</el-button>
              <el-button @click="showDialog2('upload',scope.row)" type="text" size="small">工艺上传列表</el-button>
            </template>
          </processPlanList>
        </el-tab-pane>

        <el-tab-pane label="29所工艺" name="2" v-if="dialog.type==='update'">
          <!-- <el-button type="primary" @click="showDialog1('insert')">新增</el-button> -->
         <processPlanList29 :data="dialog.formData" ref="processPlanList29Ref">
              <template v-slot:default="scope">
                <el-button @click="showDialog1('update',scope.row)" type="text" size="small">详情</el-button>
              </template>
          </processPlanList29>
        </el-tab-pane>

        <el-tab-pane label="图纸上传" name="3" v-if="dialog.type==='update'">
          <uploadList :upLoadType="1" :drawNo="dialog.drawCode"  ref="drawing"></uploadList>
        </el-tab-pane>
        <el-tab-pane label="工艺上传" name="4" v-if="dialog.type==='update'">
           <uploadList :upLoadType="2" :drawNo="dialog.drawCode"  ref="technology"></uploadList>
        </el-tab-pane>
        <el-tab-pane label="图形文件上传" name="5" v-if="dialog.type==='update'">
           <uploadList :upLoadType="3" :drawNo="dialog.drawCode"  ref="graphicsFile"></uploadList>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>
    <!-- 新增编辑29所计划任务详情 -->
    <el-dialog class="bodyNopaddingTop" :title="dialog1.title" :visible.sync="dialog1.isShow" v-dialogDrag>
      <processPlanDetail29 :formData="dialog1.formData" :type="dialog1.type" :tid="dialog.formData.tid" :disabled='true'></processPlanDetail29>
    </el-dialog>

     <!-- 新增/编辑工艺编制 -->
    <el-dialog class="bodyNopaddingTop" :title="dialog2.title" :visible.sync="dialog2.isShow" v-dialogDrag @opened="dialog2Opened" :close-on-click-modal="false" >
      <div v-if="dialog2.type==='upload'">
        <uploadList :upLoadType="dialog2.formData.name" :drawNo="dialog2.formData.drawNo" :processId="dialog2.formData.id" ref="processUploadRef"></uploadList>
      </div>
      <div v-else>
        <processPlanDetail :drawCode="dialog.drawCode" :detail="dialog2.formData" :type="dialog2.type"  :editDisalbe="true"></processPlanDetail>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import pdf from 'vue-pdf';
import planApi from 'plugins/axios/planApi.js';
import baseApi from 'plugins/axios/baseApi.js';
import materielApi from 'plugins/axios/materielApi.js';
import uploadList from 'views/components/uploadList.vue' /**1-图纸上传、2-工艺上传、3-图形文件上传 的列表组件 */
import tableList29Screen from 'views/components/tableList29Screen.vue' /**29所列表组件 */
import taskDetail29 from 'views/components/taskDetail29.vue' /**29所任务详情组件 */
import processPlanList29 from 'views/components/processPlanList29.vue' /**29所工序列表组件 */
import processPlanDetail29 from 'views/components/processPlanDetail29.vue' /**29所工序详情组件 */
import processPlanList from 'views/components/processPlanList.vue' /**工艺编制列表组件 */
import processPlanDetail from 'views/components/processPlanDetail.vue' /**新增编辑工艺编制组件 */
processPlanList
export default {
  components: {
    pdf,
    uploadList,
    tableList29Screen,
    taskDetail29,
    processPlanList29,
    processPlanDetail29,
    processPlanList,
    processPlanDetail
  },
  data(){
    return {
      status:'0',
      postData:{
        isUploadDraw:1,
        isFinishProcess:1,
        isMaterialArrvie:1,
        isMaterialTailor:1,
        drawerTableList:[],
      },
      search:{
        drawCode:"",
        makeNo:"",
        code:"",
        taskSerialNo:""
      },
      dialog:{/**弹框配置 */
        title:'',
        isShow:false,
        type:'',
        formData:{},
        activeName:'2',
        otherUpDataData:{},
        tableData:[],
        drawCode:''
      },
      dialog1:{
        title:'',
        type:'',
        isShow:false,
        formData:{}
      },
      dialog2:{
        type:'',
        title:'',
        isShow:false,
        formData:{}
      },
    }
  },
  mounted(){
    this.status = this.$route.query.status;
    this.getTablList();
  },
  created(){
    
  },
  watch: {
    $route(){
      this.status = this.$route.query.status;
      this.search.drawCode="";
      this.search.makeNo="";
      this.search.taskSerialNo="";
      this.search.code="";
      this.getTablList();
    }
  },
  methods:{
    /**时间格式化 */
    timeFormatter(row, column, cellValue, index){
      return cellValue?this.timestampToTime(cellValue,'yyyy-mm-dd'):'';
    },
    /**29所计划列表 */
    getTablList(){
      let self = this;
      self.postData.drawCode=self.search.drawCode;
      self.postData.makeNo=self.search.makeNo;
      self.postData.code=self.search.code;
      self.postData.taskSerialNo=self.search.taskSerialNo;
      self.postData.isMaterialTailor=self.status;
      self.$refs.tableList29.get29TableList()
    },
    searchBtn(){
      this.getTablList();
    },
    showDialog(type,row){
      this.dialog.activeName='6';
      this.dialog.type = type;
      switch(type){
        case 'insert':
          this.dialog.isShow=true;
          this.dialog.formData={};
          this.dialog.title = '新增计划任务';
          break;
        case 'update':
          this.dialog.isShow=true;
          this.dialog.formData = row;
          this.dialog.title = '计划详情';
          this.dialog.drawCode = row.drawCode; 
          this.dialog.otherUpDataData.drawNo=row.drawCode;
          break;
        case 'print':
           this.dialog.formData = row;
           this.$refs.print1.getCgPdfData(row.id);
          break;
      } 
    },
    showDialog1(type,row){
      this.dialog1.isShow=true;
      this.dialog1.type=type;
      switch(type){
        case 'insert':
          this.dialog1.formData={};
          this.dialog1.title = '新增29所工艺详情';
          break;
        case 'update':
          this.dialog1.formData = row;
          this.dialog1.title = '编辑29所工艺详情';
          break;
      }
    },
    showDialog2(type,row){
      let self = this;
      self.dialog2.type = type;
      if(row){
        row.person=Number(row.person);
        row.checkPerson=Number(row.checkPerson);
        row.cjCheckPerson=Number(row.cjCheckPerson);
      }  
      switch(type){
        case 'update':
          self.dialog2.isShow=true;
          self.dialog2.formData=row;
          self.dialog2.title ="编辑工艺编制";
          self.dialog2.formData.draw=self.dialog2.formData.draw?self.dialog2.formData.draw:{};
           materielApi.technologyInfo({drawNo:self.dialog.drawCode}).then(res=>{
              self.dialog2.isShow=true;
              if(res.content){
                self.dialog2.formData.draw=res.content;
              }
            })
          break;
        case 'upload':
          self.dialog2.isShow=true;
          self.dialog2.formData=row;
          self.dialog2.title ="工艺上传列表";
          break;
      }
    },
    /**详情切换tab*/ 
    dialogHandleClick(){
      let self = this;
      switch(self.dialog.activeName){
        case '2':
          self.$refs.processPlanList29Ref.getProcessPlanList();
          break;
         case '3':
           self.$refs.drawing.getTableList();
          break;
         case '4':
           self.$refs.technology.getTableList();
          break;
        case '5':
          self.$refs.graphicsFile.getTableList();
          break;
        case '6':
          self.$refs.processPlanListRef.getProcessPlanList();
          break;
      }
    },
    /**打开弹框*/ 
    openedDialog(){
      if(this.dialog.type==='update'&&this.dialog.activeName==='6'){
        this.$refs.processPlanListRef.getProcessPlanList();
      }
    },
    dialog2Opened(){
      this.dialog2.type==='upload'?this.$refs.processUploadRef.getTableList():'';
    },
    /**确认下料*/ 
    confirmHandle(row){
      let self  = this;
      self.$confirm('是否确认已下料?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        materielApi.materialTailor(row.id).then(res=>{
          self.$message.success("确认成功")
          self.getTablList();
        })
      }).catch(()=>{})
    }
  }
}
</script>
<style lang="stylus" scoped>
  .addRole
    padding-bottom 10px
</style>